﻿
namespace SessionHunter.Model
{
    /// <summary>
    /// Stores the information about a reference to an external assembly
    /// </summary>
    public class ExternalReference
    {
        /// <summary>
        /// The full name of the assembly.
        /// e.g. 'TestDataGenerator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        /// <remarks>Treated as a unique key</remarks>
        public string FullAssemblyName
        {
            get;
            set;
        }

        /// <summary>
        /// The path to the assembly
        /// </summary>
        public string Path
        {
            get;
            set;
        }

        /// <summary>
        /// Any error we encountered during the load
        /// </summary>
        public string Error
        {
            get;
            set;
        }

        #region Equals
        /// <summary>
        /// Will be equal if they point to the same path
        /// </summary>
        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return false;
            }

            // If parameter cannot be cast to Point return false.
            ExternalReference p = obj as ExternalReference;
            if ((System.Object)p == null)
            {
                return false;
            }

            // Return true if the paths to assemblies match:
            return (Path == p.Path);
        }

        /// <summary>
        /// Will be equal if they point to the same path
        /// </summary>
        public bool Equals(ExternalReference p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return false;
            }

            // Return true if the paths to assemblies match:
            return (Path == p.Path);
        }

        /// <summary>
        /// Returns a hash code based on the path to the assembly
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return Path.GetHashCode();
        }
        #endregion
    }
}
